<?php

declare(strict_types=1);

/**
 * Author: Jesse
 * Email : jessedev@163.com
 * Date: 2024/6/15 10:51
 * FileName: base.php
 * DESC: The Relentless Pursuit of Perfection.
 */

use function Hyperf\Collection\value;
use function Hyperf\Support\env;

return value(function () {

    // 公共选项参数、如果需要去配置单独的，在对应配置中心配置就好
    $options = [
        'connect_timeout' => 5.0,
        'recv_timeout' => 5.0, # 客户端Rpc调用响应接受超时时间
        'settings' => [
            // 根据协议不同，区分配置
            'open_eof_split' => true,
            'package_eof' => "\r\n",
        ],
        // 这部也可以在配置中心配置
        'pool' => [
            'min_connections' => 1,
            'max_connections' => 32,
            'connect_timeout' => 10.0,
            'wait_timeout' => 3.0,
            'heartbeat' => -1,
            'max_idle_time' => 60.0,
        ],
    ];

    // 公共Nacos配置
    $registry = [
        'protocol' => 'nacos',
        'address' => 'http://' . env('NACOS_HOST') . ':' . env('NACOS_PORT'),
    ];

    // 定义的客户端消费者
    return [
        'OrderService' => [
            'interface' => ApiClient\Order\Interfaces\OrderServiceInterface::class,
            'protocol' => 'jsonrpc',
            'registry' => $registry,
            'options' => $options,
        ],
        'UserService' => [
            'interface' => ApiClient\User\Interfaces\UserServiceInterface::class,
            'protocol' => 'jsonrpc',
            'registry' => $registry,
            'options' => $options,
        ],
    ];
});